from api.add_cart import add_cartAPI
from api.litemall_login import LiteLogin
class Test_add_cart:
    token=None
    def setup_method(self):
        self.api_cart=add_cartAPI()
        self.api_login=LiteLogin()
        resp_1=self.api_login.login(test_data={"username":"user123","password":"user123"})
        Test_add_cart.token=resp_1.json().get("data")["token"]
    def terndown_method(self):
        pass
    # 测试方法
    def test01_success(self):
        test_data={"goodsId":1181000,"number":1,"productId":2}
        resp_2=self.api_cart.add_cart(token=Test_add_cart.token,test_data=test_data)
        assert 200 == resp_2.status_code
        assert 0 ==resp_2.json().get("errno")
        assert "成功" in resp_2.text
    def test02_no_goodsid(self):
        test_data = {"goodsId": "", "number": 1, "productId": 2}
        resp_2 = self.api_cart.add_cart(token=Test_add_cart.token, test_data=test_data)
        assert 200 == resp_2.status_code
        assert 401 == resp_2.json().get("errno")
        assert "不" in resp_2.text
    def test03_no_goodsnum(self):
        test_data = {"goodsId": 1181000, "number":"", "productId": 2}
        resp_2 = self.api_cart.add_cart(token=Test_add_cart.token, test_data=test_data)
        assert 200 == resp_2.status_code
        assert 502 == resp_2.json().get("errno")
        assert "错误" in resp_2.text